
package com.sm.healthy.ui.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.widget.TextView;

import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.data.CandleEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.utils.MPPointF;
import com.github.mikephil.charting.utils.Utils;
import com.sm.healthy.R;
import com.sm.healthy.data.bean.BloodPressureEntity;
import com.sm.healthy.data.bean.OxygenEntity;
import com.sm.healthy.utils.DateUtils;

import java.text.DecimalFormat;

/**
 * Custom implementation of the MarkerView.
 *
 * @author Philipp Jahoda
 */
@SuppressLint("ViewConstructor")
public class MyMarkerView extends MarkerView {

    private final TextView tv_mark;
    private final TextView tv_mark_time;
    private final TextView tv_mark2;
    private float selectX;

    public MyMarkerView(Context context, int layoutResource) {
        super(context, layoutResource);

        tv_mark = findViewById(R.id.tv_mark);
        tv_mark_time = findViewById(R.id.tv_mark_time);
        tv_mark2 = findViewById(R.id.tv_mark2);
    }

    // runs every time the MarkerView is redrawn, can be used to update the
    // content (user-interface)
    @SuppressLint("SetTextI18n")
    @Override
    public void refreshContent(Entry e, Highlight highlight) {
        if (e instanceof CandleEntry) {
            CandleEntry ce = (CandleEntry) e;
            tv_mark.setText(Utils.formatNumber(ce.getHigh(), 0, true) + "");
        } else {
//            OxygenEntity data = (OxygenEntity) e.getData();
            //            tv_mark.setText(Utils.formatNumber(e.getY(), 0, true) + "bpm");
//            tv_mark.setText(data.getOxygen() + " /");
//            tv_mark_time.setText(DateUtils.getTimeMinute(data.getTimeLong()));
            DecimalFormat decimalFormat = new DecimalFormat("0.0");
//            tv_mark2.setText(decimalFormat.format(data.getLevelOxygen()) + "");

            selectX = e.getX();
        }
    }

    @Override
    public MPPointF getOffset() {
        return new MPPointF(-(getWidth() / 2), -getHeight());
    }
}
